﻿using D.Medicalcare.ErrorCode;
using D.Medicalcare.Write.API.Application.Commands.TitleManagementCommand;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace D.Medicalcare.Write.API.Controllers
{
    /// <summary>
    /// 职称管理控制器-写
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class TitleManagementsController : ControllerBase
    {
        private     readonly IMediator mediator;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator">中介者</param>
        public TitleManagementsController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 添加职称管理
        /// </summary>
        /// <param name="request">请求参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> AddTitleManagement(AddTitleManagementCommand request)
        {
            try
            {
                return await mediator.Send(request); 
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 删除职称管理
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> DeletedTitleManagement([FromQuery]DeletedTitleManagementCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 更新职称管理
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> UpdateTitleManagement(UpdateTitleManagementCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
